package com.lwl.controller.mht;

import com.github.pagehelper.PageInfo;
import com.lwl.entity.LayData;
import com.lwl.entity.MyPage;
import com.lwl.entity.mht.TMhtRecord;
import com.lwl.entity.mht.Statistics1;
import com.lwl.entity.mht.Statistics2;
import com.lwl.service.mht.TMhtRecordService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * (TMhtRecord)表控制层
 *
 * @author Lei
 * @since 2022-10-28 19:21:00
 */
@RestController
@RequestMapping("tMhtRecord")
public class TMhtRecordController {
    /**
     * 服务对象
     */
    @Autowired
    private TMhtRecordService tMhtRecordService;

    @GetMapping("queryAll")
    public LayData queryAll(MyPage myPage, TMhtRecord tMhtRecord){
        PageInfo pageInfo = tMhtRecordService.queryAll(myPage,tMhtRecord);
        return new LayData(pageInfo);
    }

    /**
     *  展示用户的详细做题记录（题目以及对应的答案）
     * @return
     */
    @GetMapping("recordDetails/{id}")
    public LayData recordDetails(@PathVariable Integer id,MyPage myPage){
        PageInfo pageInfo = tMhtRecordService.getRecordDetails(myPage,id);
        return  new LayData(pageInfo);
    }

    /**
     * 电话号的唯一性检验：每个电话号只能用一次
     * @param tMhtRecord
     * @return
     */
    @GetMapping("checkRecord")
    public LayData checkRecord(TMhtRecord tMhtRecord){
        TMhtRecord tMhtRecords = tMhtRecordService.checkRecord(tMhtRecord);
        return new LayData(tMhtRecords);
    }

    /**
     * 添加做题记录到数据库，最后要返回添加记录的id
     */
    @PostMapping("addRecord")
    public LayData addRecord(TMhtRecord tMhtRecord){
        int insert = tMhtRecordService.insertRecord(tMhtRecord);
        return new LayData(insert);
    }


    /**
     * 获取统计的详细信息：每个人各种心理特点进行展示
     * @return
     */
    @GetMapping("statistics2")
    public LayData getStatistics2(MyPage myPage, Statistics2 statistics2){
        PageInfo pageInfo = tMhtRecordService.getStatistics2(myPage,statistics2);
        System.out.println("最后的格式是pageInfo = " + pageInfo);
        return new LayData(pageInfo);
    }

    /**
     * 获取各个心理特点占总人数占比的统计信息
     * @return
     */
    @GetMapping("statistics1")
    public LayData getStatistics1(){
        List<Statistics1> statistics1List = tMhtRecordService.getStatistics1();
        return new LayData(statistics1List);
    }

    /**
     * 回访时根据用户ID检验用户心理特点判断是否需要回访
     * @param id
     * @return
     */
    @PostMapping("queryByTestId")
    public LayData queryByTestId(Integer id){
        boolean status = tMhtRecordService.queryByTestId(id);
        return new LayData(status);
    }

}
